-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir] Implement inferResultRanges for vector.step op #151536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-vector Author: None (Max191) ChangesImplements the Full diff: https://github.com/llvm/llvm-project/pull/151536.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index 3885439e11f89..1d9a9d3f699ac 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -2876,7 +2876,10 @@ def Vector_ScanOp :
// VectorStepOp
//===----------------------------------------------------------------------===//
-def Vector_StepOp : Vector_Op<"step", [Pure]> {
+def Vector_StepOp : Vector_Op<"step", [
+ Pure,
+ DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>
+ ]> {
let summary = "A linear sequence of values from 0 to N";
let description = [{
A `step` operation produces an index vector, i.e. a 1-D vector of values of
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 8789f55707267..144091bd0f70e 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -7197,6 +7197,31 @@ Value mlir::vector::makeArithReduction(OpBuilder &b, Location loc,
return selectPassthru(b, mask, result, acc);
}
+//===----------------------------------------------------------------------===//
+// StepOp
+//===----------------------------------------------------------------------===//
+
+void StepOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
+ SetIntRangeFn setResultRanges) {
+ auto resultType = cast<VectorType>(getType());
+ if (resultType.isScalable()) {
+ return;
+ }
+ std::optional<ConstantIntRanges> result;
+ Type elementType = resultType.getElementType();
+ unsigned bitwidth = elementType.isIndex()
+ ? IndexType::kInternalStorageBitWidth
+ : elementType.getIntOrFloatBitWidth();
+ int64_t size = resultType.getShape()[0];
+ for (int64_t val : llvm::seq<int64_t>(size)) {
+ auto range = ConstantIntRanges::constant(APInt(bitwidth, val));
+ result = (result ? result->rangeUnion(range) : range);
+ }
+
+ assert(result && "Zero-sized vectors are not allowed");
+ setResultRanges(getResult(), *result);
+}
+
//===----------------------------------------------------------------------===//
// Vector Masking Utilities
//===----------------------------------------------------------------------===//
diff --git a/mlir/test/Dialect/Vector/int-range-interface.mlir b/mlir/test/Dialect/Vector/int-range-interface.mlir
index 2563b48cdd506..c60c21fadb668 100644
--- a/mlir/test/Dialect/Vector/int-range-interface.mlir
+++ b/mlir/test/Dialect/Vector/int-range-interface.mlir
@@ -99,3 +99,11 @@ func.func @test_vector_extsi() -> vector<2xi32> {
%2 = test.reflect_bounds %1 : vector<2xi32>
func.return %2 : vector<2xi32>
}
+
+// CHECK-LABEL: func @vector_step
+// CHECK: test.reflect_bounds {smax = 7 : index, smin = 0 : index, umax = 7 : index, umin = 0 : index}
+func.func @vector_step() -> vector<8xindex> {
+ %0 = vector.step : vector<8xindex>
+ %1 = test.reflect_bounds %0 : vector<8xindex>
+ func.return %1 : vector<8xindex>
+}
|
Signed-off-by: Max Dawkins <[email protected]>
97c5c34 to
ff1cac2
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/138/builds/16912 Here is the relevant piece of the build log for the reference |
Implements the
inferResultRangesmethod from theInferIntRangeInterfaceinterface forvector.step. The implementation is similar to that of arith.constant, since the exact result values are statically known.